function generic_scatter(logPlotFlag,xbins,xrange,ybins,yrange,data1,data2,label)
% function generic_scatter(logPlotFlag,numbins,numScaledBins,data1,data2)
plot_fig=figure;

set(gcf, 'PaperUnits', 'centimeters');
set(gcf, 'PaperSize', [7 7]);
set(gcf, 'PaperPositionMode', 'manual');
set(gcf, 'PaperPosition', [0 0 7 7]);

binReductionX=xrange(2)/xbins;
binReductionY=yrange(2)/ybins;

dens = zeros(xbins,ybins);

%dens = zeros(numScaledBins,numScaledBins);

%This rebins the data, by increasing the count in an index of a matix.
%The bins are resized so the matix is not incredibly large

if(logPlotFlag)
    for i=1:length(data1)
        x = max(fix(log(data1(i))*(numScaledBins/log(numbins))),1);
        y = max(fix(log(data2(i))*(numScaledBins/log(numbins))),1);
        dens(y,x) = dens(y,x) + 1;
    end    
    fsc_axis = 0:1:(numScaledBins-1)*binReduction;
    fl1_axis = 0:1:(numScaledBins-1)*binReduction;
else
    for i=1:length(data1)
        x = max(fix(data1(i)/binReductionX),1);
        x = min(x,xbins);
        y = max(fix(data2(i)/binReductionY),1);
        y = min(y,ybins);
        dens(y,x) = dens(y,x) + 1;
    end
    fsc_axis = ([0:1:(xbins-1)]*binReductionX);
    fl1_axis = ([0:1:(ybins-1)]*binReductionY);
end

gca=imagesc(fsc_axis, fl1_axis, log(dens+1), [0 4]);
axis xy
axis([xrange(1) xrange(2) yrange(1) yrange(2)])

%xlabel(label{1},'FontName','Arial','FontSize',12)
%ylabel(label{2},'FontName','Arial','FontSize',12)
%title(label{3},'FontName','Arial','FontSize',12)

%set(gca,'FontName','Arial','FontSize',12)
%set(gca,'Color','none');
set(gcf, 'Color', 'none');

%print(gcf, '-depsc', label{4});
    
%xlabel([params.par(indicesToPlot(1)).name,' v:',num2str(params.par(indicesToPlot(1)).voltage)]);
%ylabel([params.par(indicesToPlot(2)).name,' v:',num2str(params.par(indicesToPlot(2)).voltage)]);
%title([params.experiment,' ', params.specimen,' ',params.tube,': '...
%   params.par(indicesToPlot(1)).name,' vs ',params.par(indicesToPlot(2)).name, ' scatter']);